const router = require("koa-router")();
const DB = require("../../module/db.js");

/**
 * 获取文章列表
 * api/article/getArticles
*/
router.get("/getArticles", async (ctx) => {
  let page = ctx.query.page || 1;
  let pageSize = 8;
  let result = await DB.find("article", {}, {}, pageSize, page, {'add_time': -1});
  let totleNum = await DB.count("article", {});
  let totlePages = Math.ceil(totleNum / pageSize);
  ctx.body = {
    code: 200,
    data: result,
    meta: {
      totalPages: totlePages,
      total: totleNum
    }
  }
});
module.exports=router.routes();